package com.woniu.search.controller;

import com.woniu.cinema.domain.Actor;
import com.woniu.cinema.domain.Cinema;
import com.woniu.cinema.vo.MovieVo;
import com.woniu.common.core.domain.AjaxResult;
import com.woniu.search.entity.ActorSearch;
import com.woniu.search.entity.CinemaSearch;
import com.woniu.search.entity.MovieSearch;
import com.woniu.search.entity.Test;
import com.woniu.search.repository.TestRepository;
import com.woniu.search.service.SearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author 杨光 微信号:tolryg
 * @time 10:39
 */

@RestController
public class SearchController {

    @Autowired
    private TestRepository testRepository;


    @Autowired
    private ElasticsearchRestTemplate elasticsearchRestTemplate;


    @Autowired
    private SearchService searchService;

    @RequestMapping("/web/search/movie/list")
    public AjaxResult searchMovie(String searchKey){

        return searchService.searchMovie(searchKey);
    }
    @RequestMapping("/web/search/actor/list")
    public AjaxResult searchActor(String searchKey){

        return searchService.searchActor(searchKey);
    }
    @RequestMapping("/web/search/cinema/list")
    public AjaxResult searchCiname(String searchKey){

        return searchService.searchCiname(searchKey);
    }

    @RequestMapping("/search/movie")
    public List<MovieVo> queryMovieVoByMovieId(Integer movieId){
        System.out.println("movieId = " + movieId);
        return searchService.queryMovieVoByMovieId(movieId);
    }

    @RequestMapping("/search/cinema")
    public List<Cinema> queryCinemaByCinemaId(Integer cinemaId){
        System.out.println("cinemaId = " + cinemaId);
        return searchService.queryCinemaByCinemaId(cinemaId);
    }

    @RequestMapping("/search/actor")
    public List<Actor> queryActorByActorId(Integer actorId){
        System.out.println("actorId = " + actorId);
        return searchService.queryActorByActorId(actorId);
    }
    @RequestMapping("/search/refreshCinema")
    public void refreshCinema(Integer cinemaId){
        searchService.refreshCinema(cinemaId);
    }
    @RequestMapping("/search/refreshActor")
    public void refreshActor(Integer actorId){
        searchService.refreshActor(actorId);
    }

    @RequestMapping("/search/refreshMovie")
    public void refreshMovie(Integer movieId){
        searchService.refreshMovie(movieId);
    }

    @GetMapping("testindex")
    public void testIndex(){
//        elasticsearchRestTemplate.deleteIndex(Test.class);
        elasticsearchRestTemplate.createIndex(ActorSearch.class);
        elasticsearchRestTemplate.createIndex(CinemaSearch.class);
        elasticsearchRestTemplate.createIndex(MovieSearch.class);
        elasticsearchRestTemplate.putMapping(ActorSearch.class);
        elasticsearchRestTemplate.putMapping(CinemaSearch.class);
        elasticsearchRestTemplate.putMapping(MovieSearch.class);


    }
}
